<%-- 
    Document   : raportTmpl
    Created on : Feb 13, 2014, 12:45:45 PM
    Author     : Marek
--%>
<%@page import="entities.users.FormSigner"%>
<%@page import="entities.tools.Form"%>
<%@page import="entities.tools.FilledForm"%>
<%@page import="entities.tools.Answer"%>
<%@page import="util.other.ENUMQuestionTypes"%>
<%@page import="entities.tools.Question"%>
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html;charset=UTF-8" language="java" %>
<%@page isELIgnored="false" %> 
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<!DOCTYPE html>

<form method="POST" action="<c:url value="?generate=true"/>"/>
    <input name="formName" value="form" type="hidden"/>
    <div style="width:97%;height:10%">
        First name: <input type="text" name="firstName" value=""/>
        Second name: <input type="text" name="secondName" value=""/>
        Phone name: <input type="text" name="phone" value=""/>
        Email: <input type="text" name="email" value=""/>
        <input type="submit" value="Generate the link"/>
    </div>
    
    //TODO:How to generate this generatedFormUrl in easy way
    <div style="width:97%;height:10%;color:red;">${generatedFormUrl}</div>
    <div style="width:97%;height:80%;overflow:auto;">
        <table border="1" style="width:100%;font-size:10px;">
            <tr>
                <th>First name</th>
                <th>Second name</th>
                <th>Phone</th>
                <th>Email</th>
                <th>When created</th>
                <th>If filled</th>
                <th>When filled</th>
                <th></th>
            </tr>
            <c:forEach items="${lastlyCreatedFilledForms}" var="filledForm">
                <c:set var="formSigner" value="${filledForm.formSigner}"/>
                <tr>
                    <td>${formSigner.firstName}</td>
                    <td>${formSigner.secondName}</td>
                    <td>${formSigner.phone}</td>
                    <td>${formSigner.email}</td>
                    <td><fmt:formatDate value="${filledForm.whenCreated}" pattern="yyyy-MM-dd HH:mm:ss" /></td>
                    <c:set var="url" value="http://${pageContext.request.serverName}:${pageContext.request.localPort}${pageContext.request.contextPath}/form.jsp?linkHash=${filledForm.linkHash}"/>
                    <c:set var="url" value="${fn:replace(url,'https:','http:')}"/>
                    <c:set var="url" value="${fn:replace(url,':443','')}"/>
                    <c:set var="url" value="${fn:replace(url,':8181',':8080')}"/>
                    <td><a href="${url}">${url}</a></td>
                        <c:choose>
                            <c:when test="${filledForm.formWasFilled==true}">
                            <td>filled</td>
                            <td><fmt:formatDate value="${filledForm.whenFilled}" pattern="yyyy-MM-dd HH:mm:ss" /></td>
                            <td>&nbsp;</td>
                        </c:when>
                        <c:otherwise>
                            <td>waiting</td>
                            <td>&nbsp;</td>
                            <td><a href="<c:url value="?action=delete&attribute1=${filledForm.id}"/>">Delete</a></td>
                        </c:otherwise>
                    </c:choose>
                    
                </tr>
            </c:forEach>
        </table>
    </div>
</form>
